package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppUserWhitelist;
import com.ruoyi.system.service.IAppUserWhitelistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * app用户-白名单Controller
 *
 * @author ruoyi
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/system/whitelist")
public class AppUserWhitelistController extends BaseController {
    @Autowired
    private IAppUserWhitelistService appUserWhitelistService;

    /**
     * 查询app用户-白名单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppUserWhitelist appUserWhitelist) {
        startPage();
        List<AppUserWhitelist> list = appUserWhitelistService.selectAppUserWhitelistList(appUserWhitelist);
        return getDataTable(list);
    }

    /**
     * 导出app用户-白名单列表
     */
    @Log(title = "app用户-白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppUserWhitelist appUserWhitelist) {
        List<AppUserWhitelist> list = appUserWhitelistService.selectAppUserWhitelistList(appUserWhitelist);
        ExcelUtil<AppUserWhitelist> util = new ExcelUtil<AppUserWhitelist>(AppUserWhitelist.class);
        util.exportExcel(response, list, "app用户-白名单数据");
    }

    /**
     * 获取app用户-白名单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appUserWhitelistService.selectAppUserWhitelistById(id));
    }

    /**
     * 新增app用户-白名单
     */
    @Log(title = "app用户-白名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppUserWhitelist appUserWhitelist) {
        return toAjax(appUserWhitelistService.insertAppUserWhitelist(appUserWhitelist));
    }

    /**
     * 修改app用户-白名单
     */
    @Log(title = "app用户-白名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppUserWhitelist appUserWhitelist) {
        return toAjax(appUserWhitelistService.updateAppUserWhitelist(appUserWhitelist));
    }

    /**
     * 删除app用户-白名单
     */
    @Log(title = "app用户-白名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appUserWhitelistService.deleteAppUserWhitelistByIds(ids));
    }
}
